home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / disk / initializeQueues.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.7 KB  |  182 lines

  1. /*
  2.  *   $RCSfile: initializeQueues.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:38 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "queue_consist.h"
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "list.h"
  42. #include "error.h"
  43. #include "tid.h"
  44. #include "pool.h"
  45. #include "io.h"
  46. #include "bitvec.h"
  47. #include "lock.h"
  48. #include "msgdefs.h"
  49. #include "disk.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "latch.h"
  53. #include "bf.h"
  54. #include "link.h"
  55. #include "volume.h"
  56. #include "trace.h"
  57. #include "msgvector.h"
  58. #include "disk_funcs.h"
  59. #include "disk_globals.h"
  60. #include "io_globals.h"
  61. #include "msg_globals.h"
  62. #include "sharedmem_globals.h"
  63. #include "queue_globals.h"
  64.  
  65. #ifdef DEBUG
  66. void
  67. dumpQueue( QUEUEPAIR *q )
  68. {
  69.     register int n;
  70.  
  71.     fprintf(stderr, 
  72.     "q 0x%x, to.magic 0x%x to.mutex.magic 0x%x, from.magic 0x%x, from.mutex.magic 0x%x",
  73.         q, q->toDisk.magic, q->toDisk.mutex.magic, q->fromDisk.magic,
  74.             q->fromDisk.mutex.magic );
  75.     n = q->toDisk.front - q->toDisk.back;
  76.     if (n<0) n = 0-n;
  77.     fprintf(stderr, "\tTO: %d ",n);
  78.     n = q->fromDisk.front - q->fromDisk.back;
  79.     if (n<0) n = 0-n;
  80.     fprintf(stderr, "\tFROM: %d ",n);
  81.     fprintf(stderr, "\n");
  82. } /* dumpQ */
  83. #endif DEBUG
  84.  
  85.  
  86. QUEUEPAIR *
  87. _diskQueue(int i, BOOL check)
  88. {
  89.     QUEUEPAIR     *qp = (QUEUEPAIR *)(ShmDiskQueues + (i * QPairSize));
  90.  
  91.     if(check) {
  92.         CHECK_QUEUE_MAGIC(&(qp->fromDisk)); 
  93.         CHECK_QUEUE_MAGIC(&(qp->toDisk)); 
  94.     }
  95.     
  96.     return  qp;
  97. }
  98.  
  99.  
  100. QUEUEPAIR *
  101. diskQueue(int i)
  102. {
  103.     return _diskQueue(i, TRUE);
  104. }
  105.  
  106. QUEUEPAIR *
  107. initDiskQueue(int i, VOLREC *volRec)
  108. {
  109.     QUEUEPAIR *qp;
  110.  
  111.     qp =   _diskQueue(i, FALSE);
  112.     bzero((char *)qp, sizeof (QUEUEPAIR));
  113.  
  114.     qp->volRec = volRec;
  115.     qp->semNum = i;
  116.  
  117.     INIT_QUEUE_MAGIC(&(qp->toDisk));
  118.     INIT_QUEUE_MAGIC(&(qp->fromDisk));
  119.     /*
  120.      * Initialize the array of elements.
  121.      * First make elements point to the rest of the space 
  122.      * between this disk q and the next.
  123.      * The amount of space here should be sizeof(ShmOffset)*NumMsgBufs.
  124.      */
  125.     qp->elements = (ShmOffset)(&qp->elements);
  126.     qp->elements++;
  127.  
  128.     return qp;
  129. }
  130.  
  131. void
  132. initializeQueues()
  133. {
  134.     /*  
  135.      * this relies on bf_Initialize() already
  136.      * having got all the shared memory and set the offset.
  137.      */
  138. #ifdef DISKPROC_MAKE
  139.     error -- this is for server only -- 
  140.     the disk process does not have volRecs and such.
  141. #endif DISKPROC_MAKE
  142.  
  143.     TRACE(TR_INIT, TR_LEVEL_1);
  144.     SM_ASSERT(LEVEL_1, (ShmDiskQueues!=NULL));
  145.  
  146.     process_identity.me = SERVER_PROC;
  147.     process_identity.other =  (1 - process_identity.me);
  148.  
  149.     /*
  150.      * get the semaphores.  First try w/o creating it.
  151.      */
  152. #define SEMPERM    0600 /* owner r/w */
  153.  
  154.     SemKey = IPC_PRIVATE;
  155.  
  156.     SemId = semget(SemKey, NumVolumes, SEMPERM);
  157.     if((SemId < 0) && (errno == ENOENT)) {
  158.         /*
  159.          * SemId does not exist. Try to create it.
  160.          */
  161.         TRPRINT(TR_INIT, TR_LEVEL_1, ("Couldn't get SemId w/o IPC_CREAT"));
  162.         errno = 0;
  163.         SemId = semget(SemKey, NumVolumes, SEMPERM | IPC_CREAT);
  164.     }
  165.     if(SemId < 0) {
  166.         TRPRINT(TR_INIT, TR_LEVEL_1, ("Couldn't get SemId with IPC_CREAT"));
  167.         fprintf(sm_ErrorStream, "SERVER error: could not allocate shared memory.\n");
  168.         fprintf(sm_ErrorStream, "\tUse ipcs and ipcrm to free old shared memory segments.\n");
  169.         SM_ERROR(TYPE_STOP, errno);
  170.     }
  171.     TRPRINT(TR_INIT, TR_LEVEL_1, ("SemId 0x%x, key 0x%x", SemId, SemKey));
  172.  
  173.     /* 
  174.      * the semaphore for replies to the server from the disk processes
  175.      */
  176.     Replies = (MUTEX *)ShmReplies;
  177.     bzero((char*)Replies, sizeof Replies);
  178.     INIT_MUTEX_MAGIC(Replies);
  179.  
  180. } /* initializeQueues */
  181.  
  182.